export default {
  namespaced: true, //命名空间
  state: {
    showToast: false,
    toastTimer: null,
    toastDesc: ''
  },
  getters: {
    showToast: (state:any) => state.showToast,
    toastDesc: (state:any) => state.toastDesc
  },
  mutations: {
    showToast(state:any, toastDesc:any) {
      const duration = 1000
      if (state.toastTimer) {
        window.clearTimeout(state.toastTimer)
        state.toastTimer = null
      }
      state.toastDesc = toastDesc
      state.showToast = true
      state.toastTimer = window.setTimeout(() => {
        window.clearTimeout(state.toastTimer)
        state.toastTimer = null
        state.showToast = false
      }, duration)
    }
  }
}